<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends CController
{
	/**
	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',
	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
	 */
	public $layout='//layouts/column1';
	/**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu=array();
	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();
	
	
	protected function _get_ins_attributes($router_control = NULL)
	{
		$router_control === NULL &&
			$router_control = lcfirst(substr(get_class($this), 0, -10)); // Controller len 10
		
		return array(
			"{$router_control}_is_active" => 1,
			"{$router_control}_is_del" => 0,
			"{$router_control}_ins_user_id" => Yii::app()->session['user_id'],
			"{$router_control}_ins_user_name" => Yii::app()->session['user_name'],
			"{$router_control}_ins_date" => $_SERVER['REQUEST_TIME'],
			
			"{$router_control}_up_user_id" => Yii::app()->session['user_id'],
			"{$router_control}_up_user_name" => Yii::app()->session['user_name'],
			"{$router_control}_up_date" => $_SERVER['REQUEST_TIME'],
		);
	}
	
	protected function _get_up_attributes($router_control = '')
	{
		$router_control === '' &&
			$router_control = lcfirst(substr(get_class($this), 0, -10)); // Controller len 10
		
		return array(
			"{$router_control}_up_user_id" => Yii::app()->session['user_id'],
			"{$router_control}_up_user_name" => Yii::app()->session['user_name'],
			"{$router_control}_up_date" => $_SERVER['REQUEST_TIME'],
		);
	}
	
	/**
	 * Element
	 *
	 * Lets you determine whether an array index is set and whether it has a value.
	 * If the element is empty it returns FALSE (or whatever you specify as the default value.)
	 *
	 * @access	public
	 * @param	string
	 * @param	array
	 * @param	mixed
	 * @return	mixed	depends on what the array contains
	 */
	protected static function element($item, $array, $default = NULL)
	{
		if (isset($array[$item]))
		{
			return $array[$item];
		}
		elseif ($default === NULL)
		{
			return current($array);
		}
		else
		{
			return $default;
		}
	}
}